# frozen_string_literal: true

module Fxlang
  class Template
    attr_reader :script, :options, :generator, :parser

    def initialize(script, pack: false, unpack: false)
      @script = script
      @options = { pack: pack, unpack: unpack }

      compile
    end

    def pack(metadata)
      generator.pack(metadata)
    end

    def unpack(target)
      parser.parse(target)
    end

    def compile
      @generator = Fxlang::Generator.new(script) if options[:pack]
      @parser = Fxlang::Parser.new(script) if options[:unpack]
    end
  end
end
